package tests;

import Common.Utils;
import org.openqa.selenium.Alert;
import org.openqa.selenium.By;

public class ListPage extends Utils {

    public static String url = "http://127.0.0.1:8080/list.html";

    public ListPage() {
        super(url);
    }

    //检查页面是否加载成功
    public void ListPageRight() {
        //通过查看页面元素是否存在来检查页面加载成功与否
        driver.findElement(By.cssSelector("#body > div.container > h3"));
    }

    //播放音乐
    public void MusicPlayBack() {
        try {
            driver.findElement(By.cssSelector("#info > tr:nth-child(1) > td:nth-child(4) > button")).click();
            Thread.sleep(10000);
        } catch (Exception e) {
            System.out.println("没有可播放的音乐MusicPlayBack");
        }
    }

    //添加喜欢列表
    public void AddLoveMusic() {
        try {
            driver.findElement(By.cssSelector("#info > tr:nth-child(1) > td:nth-child(5) > button:nth-child(2)")).click();
            Thread.sleep(2000);
            Alert alert = driver.switchTo().alert();
            alert.accept();
        } catch (Exception e) {
            System.out.println("没有可播放的音乐AddLoveMusic");
        }
    }

    //搜索音乐
    public void QueryMusic() throws InterruptedException {

        driver.findElement(By.cssSelector("#exampleInputName2")).sendKeys("小半");
        driver.findElement(By.cssSelector("#submit1")).click();
        Thread.sleep(2000);
        driver.findElement(By.cssSelector("#exampleInputName2")).clear();
        driver.findElement(By.cssSelector("#submit1")).click();
        Thread.sleep(2000);
    }
}
